package com.ruoyi.report_lqn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_lqn.domain.bo.ReportLqnSdrdjlbBsInfoBo;
import com.ruoyi.report_lqn.domain.vo.ReportLqnSdrdjlbBsInfoVo;
import com.ruoyi.report_lqn.domain.ReportLqnSdrdjlbBsInfo;
import com.ruoyi.report_lqn.mapper.ReportLqnSdrdjlbBsInfoMapper;
import com.ruoyi.report_lqn.service.IReportLqnSdrdjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 沥青闪点与燃点试验检测记录（克利夫兰开口杯法）Service业务层处理
 *
 * @author tll
 * @date 2024-09-12
 */
@RequiredArgsConstructor
@Service
public class ReportLqnSdrdjlbBsInfoServiceImpl implements IReportLqnSdrdjlbBsInfoService {

    private final ReportLqnSdrdjlbBsInfoMapper baseMapper;

    /**
     * 查询沥青闪点与燃点试验检测记录（克利夫兰开口杯法）
     */
    @Override
    @FIllBasicInfo
    public ReportLqnSdrdjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询沥青闪点与燃点试验检测记录（克利夫兰开口杯法）列表
     */
    @Override
    public TableDataInfo<ReportLqnSdrdjlbBsInfoVo> queryPageList(ReportLqnSdrdjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLqnSdrdjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportLqnSdrdjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询沥青闪点与燃点试验检测记录（克利夫兰开口杯法）列表
     */
    @Override
    public List<ReportLqnSdrdjlbBsInfoVo> queryList(ReportLqnSdrdjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportLqnSdrdjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLqnSdrdjlbBsInfo> buildQueryWrapper(ReportLqnSdrdjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLqnSdrdjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportLqnSdrdjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportLqnSdrdjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportLqnSdrdjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportLqnSdrdjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportLqnSdrdjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportLqnSdrdjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportLqnSdrdjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportLqnSdrdjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportLqnSdrdjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportLqnSdrdjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportLqnSdrdjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportLqnSdrdjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportLqnSdrdjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportLqnSdrdjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportLqnSdrdjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportLqnSdrdjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportLqnSdrdjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportLqnSdrdjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportLqnSdrdjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportLqnSdrdjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportLqnSdrdjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportLqnSdrdjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportLqnSdrdjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportLqnSdrdjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportLqnSdrdjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportLqnSdrdjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportLqnSdrdjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getQuydd()), ReportLqnSdrdjlbBsInfo::getQuydd, bo.getQuydd());
        lqw.eq(StringUtils.isNotBlank(bo.getLiqcd()), ReportLqnSdrdjlbBsInfo::getLiqcd, bo.getLiqcd());
        lqw.eq(StringUtils.isNotBlank(bo.getLiqzlbh()), ReportLqnSdrdjlbBsInfo::getLiqzlbh, bo.getLiqzlbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJilcdmc()), ReportLqnSdrdjlbBsInfo::getJilcdmc, bo.getJilcdmc());
        lqw.eq(StringUtils.isNotBlank(bo.getShiycs1()), ReportLqnSdrdjlbBsInfo::getShiycs1, bo.getShiycs1());
        lqw.eq(bo.getShandwd1() != null, ReportLqnSdrdjlbBsInfo::getShandwd1, bo.getShandwd1());
        lqw.eq(bo.getRandwd1() != null, ReportLqnSdrdjlbBsInfo::getRandwd1, bo.getRandwd1());
        lqw.eq(bo.getShand1() != null, ReportLqnSdrdjlbBsInfo::getShand1, bo.getShand1());
        lqw.eq(bo.getRand1() != null, ReportLqnSdrdjlbBsInfo::getRand1, bo.getRand1());
        lqw.eq(StringUtils.isNotBlank(bo.getShiycs2()), ReportLqnSdrdjlbBsInfo::getShiycs2, bo.getShiycs2());
        lqw.eq(bo.getShandwd2() != null, ReportLqnSdrdjlbBsInfo::getShandwd2, bo.getShandwd2());
        lqw.eq(bo.getRandwd2() != null, ReportLqnSdrdjlbBsInfo::getRandwd2, bo.getRandwd2());
        lqw.eq(bo.getShand2() != null, ReportLqnSdrdjlbBsInfo::getShand2, bo.getShand2());
        lqw.eq(bo.getRand2() != null, ReportLqnSdrdjlbBsInfo::getRand2, bo.getRand2());
        lqw.eq(bo.getShandPjz() != null, ReportLqnSdrdjlbBsInfo::getShandPjz, bo.getShandPjz());
        lqw.eq(bo.getRandPjz() != null, ReportLqnSdrdjlbBsInfo::getRandPjz, bo.getRandPjz());
        return lqw;
    }

    /**
     * 新增沥青闪点与燃点试验检测记录（克利夫兰开口杯法）
     */
    @Override
    public Boolean insertByBo(ReportLqnSdrdjlbBsInfoBo bo) {
        ReportLqnSdrdjlbBsInfo add = BeanUtil.toBean(bo, ReportLqnSdrdjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改沥青闪点与燃点试验检测记录（克利夫兰开口杯法）
     */
    @Override
    public Boolean updateByBo(ReportLqnSdrdjlbBsInfoBo bo) {
        ReportLqnSdrdjlbBsInfo update = BeanUtil.toBean(bo, ReportLqnSdrdjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLqnSdrdjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除沥青闪点与燃点试验检测记录（克利夫兰开口杯法）
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
